//
//  AYMainViewController.swift
//  iOSSinaWeb
//
//  Created by yws on 16/5/10.
//  Copyright © 2016年 yws. All rights reserved.
//

import UIKit

class AYMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let composeCallback = { () -> () in
            
            print("Modal出控制器")
        }
        
        let mainTabBar = AYMainTabBar()
        
        
        mainTabBar.composeCallback = composeCallback

        setValue(mainTabBar, forKey: "tabBar")
        setupChilderViewController()
    }
    
    
    
    
    //设置各个控制器
    func setupChilderViewController(){
        
        //首页控制器
        let homeVC = AYHomeViewController()
        addChildViewController(homeVC, title: "主页", imageName: "tabbar_home")
        
        //消息控制器
        let messageVC = AYMessageTableViewController()
        addChildViewController(messageVC, title: "消息", imageName: "tabbar_message_center")
        
        //发现控制器
        let discoveryVC = AYDiscoveryViewController()
        addChildViewController(discoveryVC, title: "发现", imageName: "tabbar_discover")
        
        //我控制器
        let profileVC = AYProfileViewController()
        addChildViewController(profileVC, title: "我", imageName: "tabbar_profile")

    }

    //抽取后的创建每一个控制器
    func addChildViewController(Controller: UIViewController, title: String, imageName: String) {
        Controller.title = title
        Controller.tabBarItem.image = UIImage(named: imageName)
        Controller.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        Controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        addChildViewController(UINavigationController(rootViewController: Controller))
    }
}
